<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/sys/include/taglib.jsp"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>设置用户角色</title>
<%@ include file="/WEB-INF/sys/include/css.jsp" %>
</head>
<body>
<div class="form">
	<div class="title" style="margin-bottom:0;">设置用户角色</div>
	
	
	<div class="group" style="margin-bottom:0;">
		<div class="label" style="width:20px;">&nbsp;</div>
		<div class="text" style="width:360px;">可用角色:</div>
		<div class="text" style="width:60px;">&nbsp;</div>
		<div class="text">已有角色:</div>
	</div>
	<div class="group">
		<div class="label" style="width:20px;">&nbsp;</div>
		<div class="item"><div id="rolelist" style=""></div></div>
		<div class="item">
			<div style="width:60px;text-align:center;margin-top:180px;"><button type="button" class="auibtn" onclick="addRoles()">&gt;&gt;</button></div>
			<div style="width:60px;text-align:center;margin-top:20px;"><button type="button" class="auibtn" onclick="delRoles()">&lt;&lt;</button></div>
		</div>
		<div class="item"><div id="curlist" style=""></div></div>
	</div>

	<div class="buttons" style="width:440px;">
		<button type="button" id="cancel1">返回</button>
	</div>
</div>
<%@ include file="/WEB-INF/sys/include/script.jsp" %>
<script type="text/javascript">
var rolelist, curlist;
$(function (){
	rolelist = $("#rolelist").ligerGrid(ligerGridParam({
		columns: [
			{display: '角色名称', name: 'role_name', width: 170, align: 'left'},
			{display: '所属分组', name: 'groupname', width: 160, align: 'left'}
		],
		url: "${path}/user/getSetRoles.json?userid=${userid}",
		pageSize: 15,
		width: 360,
		height: 480,
		rownumbers: false,
		hideStatMessage: true
	}));
	$(".l-grid-body2:first", rolelist.gridview2).css('overflow', 'hidden');
	
	curlist = $("#curlist").ligerGrid(ligerGridParam({
		columns: [
			{display: '角色名称', name: 'role_name', width: 170, align: 'left'},
			{display: '所属分组', name: 'groupname', width: 160, align: 'left'}
		],
		url: "${path}/user/getUserRoles.json?userid=${userid}",
		pageSize: 15,
		width: 360,
		height: 480,
		rownumbers: false,
		hideStatMessage: true
	}));
	$(".l-grid-body2:first", curlist.gridview2).css('overflow', 'hidden');
	
	$("#cancel1").click(function(){
		UiUtil.closeForm();
	});
});

function addRoles(){
	var ids = getSelectedIds(rolelist, "roleid");
	if(ids.length==0){
		return;
	}
	postData('${path}/user/addUserRoles.json', {userid:"${userid}", roleid:ids}, null, null, function(data){
		if(!UiUtil.hasErrors(data)){
			rolelist.loadData(true);
			curlist.loadData(true);
		}
	});
}
function delRoles(){
	var ids = getSelectedIds(curlist, "relid");
	if(ids.length==0){
		return;
	}
	postData('${path}/user/deleteUserRoles.json', {userid:"${userid}", relid:ids}, null, null, function(data){
		if(!UiUtil.hasErrors(data)){
			rolelist.loadData(true);
			curlist.loadData(true);
		}
	});
}

</script>
</body>
</html>